package com.pug.service.redis;

import com.pug.dto.IdDto;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

/**
 * Author: lqm
 * create: 2022/5/1 17:29
 * Lover: lqx
 *
 * @see
 */
@Component
@Slf4j
public class redisSynchronize {
    /**
     * 解决redis和数据库数据不一致问题
     */
    @Qualifier("redisTemplate")
    @Autowired
    RedisTemplate<String,Object> redisTemplate;
    @RabbitListener(queues = {"liu.order.user.queue.change"},
            containerFactory = "simpleTopicOrderDeadContainerAuto")
    public void consumerOrder(@Payload IdDto idDto, Message message, Channel channel) {
        try {
            redisTemplate.delete("xq:login:user:token:"+idDto.getId());
            //将用户的token立马删除
        } catch (Exception ex) {
            log.error("删除token失败！：{}", idDto);
        }
    }
}
